import java.util.PriorityQueue;

public class Test2 {
    //leetcode 2208 将数组和减半的最少操作数
    public int halveArray(int[] nums) {
        //每次减去现在数组中最大数的一半
        PriorityQueue<Double> heap = new PriorityQueue<>((a, b) ->
                b.compareTo(a));
        double sum = 0;
        for (int n : nums) {
            heap.offer((double)n);
            sum += n;
        }
        sum /= 2.0;

        int count = 0;
        while (sum > 0) {
            double t = heap.poll() / 2.0;
            sum -= t;
            count++;
            heap.offer(t);
        }
        return count;
    }
}
